package com.way.demo.comm.result;

/**
 * @author lipingwei
 * @create 2021-07-05 13:44
 */

public enum ApiCode {
    /**
     * 成功 失败
     */
    SUCCESS(0, "操作成功"),
    FAIL(-1, "系统开小差了~~"),
    SERVLET_ERROR(-102, "servlet请求异常"),
    BAD_SQL_GRAMMAR_ERROR(-101, "sql语法错误"),

    UNAUTHORIZED(401, "非法访问"),

    NOT_PERMISSION(403, "没有权限"),

    NOT_FOUND(404, "你请求的路径不存在"),

    SYSTEM_EXCEPTION(5000,"系统异常!"),

    PARAMETER_EXCEPTION(5001,"请求参数校验异常"),

    PARAMETER_PARSE_EXCEPTION(5002,"请求参数解析异常"),

    HTTP_MEDIA_TYPE_EXCEPTION(5003,"HTTP Media 类型异常"),

    SYSTEM_LOGIN_EXCEPTION(5005,"系统登录异常"),

    ERROR_AUTH(201,"用户名或密码错误"),

    NEED_PARAM(202,"缺少参数"),

    OLD_PWD_ERROR(203,"旧密码输入错误"),

    ;

    private final Integer code;
    private final String msg;

    ApiCode(final Integer code, final String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ApiCode getApiCode(Integer code) {
        ApiCode[] ecs = ApiCode.values();
        for (ApiCode ec : ecs) {
            if (ec.getCode().equals(code)) {
                return ec;
            }
        }
        return SUCCESS;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

}

